package adminService

import (
	"gitee.com/yangguoliang001/go-gin-vue3/BO"
	"github.com/gin-gonic/gin"
)

func (a *AdminService) MyMenu(c *gin.Context, userID int32) (menuData []BO.MyMenuListBO, err error) {
	// 查询当前用户对应的菜单id列表
	adminMenuList, err := a.adminMenuDao.WhereMenuIdByAdminId(userID)
	if err != nil {
		return nil, err
	}

	// 查询菜单数据
	menuList, err := a.menuDao.QueryMenuUsedList()
	if err != nil {
		return nil, err
	}

	for _, menuItem := range menuList {
		for _, v := range adminMenuList {
			if menuItem.Id == v.MenuId {
				data := BO.MyMenuListBO{
					Id:   menuItem.Id,
					Pid:  menuItem.Pid,
					Name: menuItem.Name,
					Path: menuItem.Path,
					Icon: menuItem.Icon,
				}
				menuData = append(menuData, data)
			}
		}
	}
	return
}
